HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //usr/share/netplan/netplan_cli/cli/commands/__pycache__/migrate.cpython-312.pyc
�

nG�f�O���dZddlZddlZddlZddlZddlmZ	ddlZdZddl	m
Z
ddlZddlm
Z
Gd	�d
e
j�Zy#e$rdZY�/wxYw)znetplan migrate command line�N)�globFT)�OrderedDict�)�utilsc�J��eZdZ�fd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d	d�Z
�xZS)
�NetplanMigratec�,��t�|�dddd��y)N�migratez/Migration of /etc/network/interfaces to netplanT)�
command_id�description�leaf�testing)�super�__init__)�self�	__class__s ��6/usr/share/netplan/netplan_cli/cli/commands/migrate.pyrzNetplanMigrate.__init__%s ���
���I�%V�"�!%�	�	'�c�6�d|vrHd|vri|d<d|dvrg|dd<|djd�D]}|s�|ddxx|gz
cc<�|d=d|vrId|vri|d<d|dvrg|dd<|djd�D]}|s�|ddxx|gz
cc<�|d=yy)z�Parse dns options (dns-nameservers and dns-search) from if_options
        (an interface options dict) into the interface configuration if_config
        Mutates the arguments in place.
        zdns-nameservers�nameservers�	addresses� z
dns-search�searchN)�split)r�
if_options�	if_config�ns�domains     r�parse_dns_optionsz NetplanMigrate.parse_dns_options+s��
�
�*��I�-�+-�	�-�(��)�M�":�:�8:�	�-�(��5� �!2�3�9�9�#�>�
>�����-�(��5�"��=�5�
>��,�-��:�%��I�-�+-�	�-�(��y��7�7�57�	�-�(��2�$�\�2�8�8��=�
?�����-�(��2�v�h�>�2�	
?�
�<�(�&rc�0�d|vrT	t|d�}d|vr8|dk(s0tjd|||d�t	j
d�|d<|d=yy#t$r2tjd||d�t	j
d�Y��wxYw)z�Parse out the MTU. Operates the same way as parse_dns_options
        iface is the name of the interface, used only to print error messages
        �mtuz%s: cannot parse "%s" as an MTUrz0%s: tried to set MTU=%d, but already have MTU=%dN)�int�
ValueError�logging�error�sys�exit)r�ifacerrr!s     r�	parse_mtuzNetplanMigrate.parse_mtuHs���
�J��
��*�U�+�,��
�	�!�)�E�*:�c�*A��
�
�P�RW�Y\�^g�hm�^n�o������"�I�e���5�!����
��
�
�?��
�SX�HY�Z������
�s�A�8B�Bc��d|vrNd|vr>|d|dk(s3tjd||d|d�tjd�|d|d<|d=yy)z�Parse out the manually configured MAC.
        Operates the same way as parse_dns_options
        iface is the name of the interface, used only to print error messages
        �	hwaddress�
macaddressz0%s: tried to set MAC %s, but already have MAC %srN)r$r%r&r')rr(rrs    r�parse_hwaddresszNetplanMigrate.parse_hwaddress[so���*�$��y�(��<�1H�J�Wb�Lc�1c��
�
�P�RW�(��5�y��7N�P������&0��&=�I�l�#��;�'�%rc�<�|jjdd��|jjddd��|j|_|j	�t
r*t
jd�tjd	�|j�y)
Nz
--root-dirzOSearch for and generate configuration files in this root directory instead of /)�helpz	--dry-run�
store_truezQPrint converted netplan configuration to stdout instead of writing/changing files)�actionr/z�The `yaml` Python package couldn't be imported, and is needed for the migrate command.
To install it on Debian or Ubuntu-based system, run `apt install python3-yaml`�)�parser�add_argument�command_migrate�func�
parse_args�NO_YAMLr$r%r&r'�run_command)rs r�runzNetplanMigrate.runjs������ � ��&w�	!�	y���� � ��\�&y�	!�	{��(�(��	�������M�M�R�
S��H�H�Q�K����rc
��i}	|j|jxsd�\}}j�D�]\\}}|j�D�]B\}}tjd|||�|vr+tjd|�t
jd�|ddk(rtjd|��m|ddk(r�|jd	i�jd
i�j|i�}	|j|d|	�|j||d|	�|drLtjd|d
j|dj���t
jd�|dk(rd|	d<��/|dk(sJ�d|	d<��=|ddk(�r�|jd	i�jd
i�j|i�}	d|	vrg|	d<|j|d|	�|j||d|	�|j||d|	�|dk(�r�t!gd��}
t!gd��}t!|dj��}||
z
}
|
rz|
j#|�D]/}tjd|||�t
jd��1|
|z
D]/}tjd|||�t
jd��1d|dvr+tjd|�t
jd�d|ddvr#|ddj%d�d}|dd}nNd|dvr+tjd|�t
jd�|dd}|dddz|ddz}	t'j(|�}	t'j,|d �!�}|	dxxt�dztj0�zgz
cc<d#|dvs���|dd#|	d$<���|dk(sJ�t!gd%��}
t!gd&��}t!|dj��}||
z
}
|
rz|
j#|�D]/}tjd|||�t
jd��1|
|z
D]/}tjd|||�t
jd��1d|dvr+tjd|�t
jd�d|ddvr#|ddj%d�d}|dd}nNd|dvr+tjd|�t
jd�|dd}|dddz|ddz}	t'j2|�}	t'j4|d �!�}|	dxxt�dztj0�zgz
cc<d#|dvr|dd#|	d)<d*|dvs���|dd*d+k(rd |	d*<���|dd*d,k(rd|	d*<���|dd*d-k(r-tjd.|�t
jd����tjd/||dd*�t
jd���tjd0||d�t
jd���E��_t6j8j|jxsdd1�}|r�d|d	d2<t;j<|�}|j>rtA|�n�t6j8j|jxsdd3�}	t7jBt6j8jE|��	tI|d4�5}|jK|�ddd�tjLd7|�ntjLd8�|j>s1tjLd9||�t7jN||d:z�yy#t$r>}tjt|��t
jd�Yd}~��	d}~wwxYw#t&j*$r8}tjd|||�t
jd�Yd}~���d}~wwxYw#t&j.$r8}tjd"|||�t
jd�Yd}~��$d}~wwxYw#t&j*$r8}tjd'|||�t
jd�Yd}~���d}~wwxYw#t&j.$r8}tjd(|||�t
jd�Yd}~���d}~wwxYw#tF$rY��wxYw#1swY��xYw#tF$r/tjd5|�t
jd6�Y��@wxYw);N�rzConverting %s family %s %sz.%s: non-automatic interfaces are not supported�method�loopbackzIgnoring loopback interface %s�dhcp�network�	ethernets�optionsz2%s: option(s) %s are not supported for dhcp methodz, �inetT�dhcp4�inet6�dhcp6�staticr)�address�netmask�gateway)�	broadcast�metric�pointopoint�scopez%s: unsupported %s option "%s"z%s: unknown %s option "%s"rHz(%s: no address supplied in static method�/rrIzE%s: address does not specify prefix length, and netmask not specifiedz-%s: error parsing "%s" as an IPv4 address: %sF)�strictz-%s: error parsing "%s" as an IPv4 network: %srJ�gateway4)rHrIrJ�	accept_ra)rL�media�autoconf�privextrNzpreferred-lifetimezdad-attemptszdad-intervalz-%s: error parsing "%s" as an IPv6 address: %sz-%s: error parsing "%s" as an IPv6 network: %s�gateway6rR�0�1�2z(%s: netplan does not support accept_ra=2z#%s: unexpected accept_ra value "%s"z%s: method %s is not supportedzetc/network/interfaces�versionzetc/netplan/10-ifupdown.yaml�xzC%s already exists; remove it if you want to run the migration again�zmigration complete, wrote %sz>ifupdown does not configure any interfaces, nothing to migratez#renaming %s to %s.netplan-convertedz.netplan-converted)(�parse_ifupdown�root_dirr#r$r%�strr&r'�items�debug�
setdefaultrr-�join�keysr)�set�intersectionr�	ipaddress�IPv4Address�AddressValueError�IPv4Network�NetmaskValueError�	prefixlen�IPv6Address�IPv6Network�os�path�yaml�dump�dry_run�print�makedirs�dirname�FileExistsError�open�write�info�rename)r�netplan_config�ifaces�auto_ifaces�er(�
family_config�family�config�c�supported_opts�unsupported_opts�opts�bad_opts�unsupported�unknown�	addr_spec�net_spec�ipaddr�a�ipnetr�netplan_yaml�dest�fs                         rr5zNetplanMigrate.command_migratexs:	����	�"&�"5�"5�d�m�m�6I�r�"J��F�K�%+�L�L�N�f	 � �E�=�"/�"5�"5�"7�e
 �����
�
�:�E�6�6�R���+��M�M�"R�TY�Z��H�H�Q�K��(�#�z�1��M�M�"B�E�J��H�%��/�&�1�1�)�R�@�K�K�K�Y[�\�g�g�hm�oq�r�A��*�*�6�)�+<�a�@��(�(���y�0A�1�E��i�(��
�
�&Z�&+�T�Y�Y�v�i�7H�7M�7M�7O�-P�R��������'�%)��'�
�%��0�0�0�%)��'�
��H�%��1�&�1�1�)�R�@�K�K�K�Y[�\�g�g�hm�oq�r�A�"�!�+�)+��+���*�*�6�)�+<�a�@��N�N�5�&��*;�Q�?��(�(���y�0A�1�E���'�
*-�-N�)O��+.�/^�+_�(�"�6�)�#4�#9�#9�#;�<��#'�.�#8��#�/7�/D�/D�EU�/V�,�� '�
�
�.N�PU�W]�_j� k� #�����,�,4�6F�+F�,�� '�
�
�.J�E�SY�[b� c� #�����,�%�F�9�,=�=�#�M�M�*T�V[�\��H�H�Q�K��&��"3�I�">�>�(.�y�(9�)�(D�(J�(J�3�(O�PQ�(R�I�'-�i�'8��'C�H�(��y�0A�A� '�
�
�.u�.3�!5� #�����(.�y�(9�)�(D�I�'-�i�'8��'C�c�'I�F�S\�L]�^g�Lh�'h�H�(�%.�%:�%:�9�%E�F�
(�$-�$9�$9�(�5�$Q�E�
�+��3�v�;��+<�s�5�?�?�?S�+S�*T�T��$��y�(9�9�,2�9�,=�i�,H�A�j�M� &��0�0�0�*-�-[�)\��+.�0o�,p�(� #�6�)�#4�#9�#9�#;�<��#'�.�#8��#�/7�/D�/D�EU�/V�,�� '�
�
�.N�PU�W]�_j� k� #�����,�,4�6F�+F�,�� '�
�
�.J�E�SY�[b� c� #�����,�%�F�9�,=�=�#�M�M�*T�V[�\��H�H�Q�K��&��"3�I�">�>�(.�y�(9�)�(D�(J�(J�3�(O�PQ�(R�I�'-�i�'8��'C�H�(��y�0A�A� '�
�
�.u�.3�!5� #�����(.�y�(9�)�(D�I�'-�i�'8��'C�c�'I�F�S\�L]�^g�Lh�'h�H�(�%.�%:�%:�9�%E�F�
(�$-�$9�$9�(�5�$Q�E�
�+��3�v�;��+<�s�5�?�?�?S�+S�*T�T��$��y�(9�9�,2�9�,=�i�,H�A�j�M�&�&��*;�;�%�i�0��=��D�16��+��!'�	�!2�;�!?�3�!F�15��+��!'�	�!2�;�!?�3�!F� '�
�
�.X�Z_� `� #����� '�
�
�.S�UZ�.4�Y�.?��.L�!N� #������M�M�"B�E�6�RZ�K[�\��H�H�Q�K�Ke
 �f	 �P�G�G�L�L����!5�#�7O�P�	��34�N�9�%�i�0��9�9�^�4�L��|�|��l�#��w�w�|�|�D�M�M�$8�S�:X�Y����K�K������� 5�6� ��d�C��.�A�����-�.�
���;�T�B��L�L�Y�Z��|�|��L�L�>�	�9�U��I�I�i��-A�!A�B���E�	��M�M�#�a�&�!��H�H�Q�K�K��	��Z )�:�:�(�#�M�M�*Y�[`�bk�mn�o��H�H�Q�K�K��(�� )�:�:�(�#�M�M�*Y�[`�bj�lm�n��H�H�Q�K�K��(��l )�:�:�(�#�M�M�*Y�[`�bk�mn�o��H�H�Q�K�K��(�� )�:�:�(�#�M�M�*Y�[`�bj�lm�n��H�H�Q�K�K��(��N'�����.�.��&� ��M�M�"g�im�n��H�H�Q�K� �s��"_-�:`7�b�c�/d!�*2e/�f�)e?�;f�-	`4�63`/�/`4�7b�
-a=�=b�c�-c�c�d�&-d�d�!e,�4-e'�'e,�/	e<�;e<�?f	�f�4g�gc���d�}g}t|�dz}	t|dz|z�5}tjd|j�|D�]\}|j�}|r|j
d�r�(|j
d�r�tjd�}||tjj|j�|�}	tj|	�D]J}|j|�s�||j|tjj|	|d|��z
}�L��|j
d	�rYt!||tjj|j�|��D]}||j|||d�z
}���L|j#|���_	ddd�|S#1swY|SxYw#t$$rtjd
||�Y|SwxYw)zvReturn normalized lines from ifupdown config

        This resolves "source" and "source-directory" includes.
        c�d�|j�d}|jd�r||zS|dz|zS)Nr2rO)r�
startswith)�rootdir�curdir�line�args    r�expand_source_argzCNetplanMigrate._ifupdown_lines_from_file.<locals>.expand_source_argGs6���*�*�,�q�/�C��~�~�c�"���}�$���|�c�)�)rr2rOz
reading %s�#zsource-directory z^[a-zA-Z0-9_-]+$Nzsource z%s/%s does not exist, ignoring)�lenrxr$ra�name�stripr��re�compilerorprv�listdir�match�_ifupdown_lines_from_filercr�append�FileNotFoundError)
rr�rpr��lines�rootdir_lenr�r��valid_re�ds
          rr�z(NetplanMigrate._ifupdown_lines_from_fileBs���
	*����'�l�Q�&��	K��g��m�d�*�+�
+�q��
�
�l�A�F�F�3��+�D��:�:�<�D��4�?�?�3�#7� ����':�;�#%�:�:�.@�#A��-�g�r�w�w���q�v�v�7N�PT�U��!#���A��s�A�'�~�~�a�0� %��)G�)G��QS�QX�QX�Q]�Q]�^_�`k�`l�^m�op�Qq�)r� r��s�����3�!%�&7�������QR�QW�QW�AX�Z^�&_�!`�^�A�!�T�%C�%C�G�Q�{�|�_�%]�]�E�^����T�*�!+�
+�*��+
+�*���!�	K��M�M�:�G�T�J���	K�s6�G�CF4�2B7F4�*G�4F>�9G�>G� G%�$G%c	��ddddddd�}|j|d�}t�}t�}d}d}|D�]}|j�}		||	d}
t	j
d|	|
�d}d}t|	�|
dzk7r td|
|	dt|	�dz
fz��|	dd
vr|j|	d���|	ddk(rtd��|	ddk(r��|	ddk(rb|	ddvrtd|	dz��|	ddvrtd|	dz��|	d}|	d}|	did�|j|	dt��|<��td|	dz��t	j
d||�||fS#t$rR|r>t	j
d||�|jd�	�d|||d
|	d<Y���td|	dz��wxYw)uWParse ifupdown configuration.

        Return (iface_name →  family → {method, options}, auto_ifaces: set) tuple
        on successful parsing, or a ValueError when encountering an invalid file or
        ifupdown features which are not supported (such as "mapping").

        options is itself a dictionary option_name → value.
        r2r\)�auto�
allow-auto�
allow-hotplug�mapping�
no-scriptsr(z/etc/network/interfacesNrz$line fields %s (expected length: %i)z$in_options %s, parsing as option: %s)�maxsplitrBzUnknown stanza type %sz0Expected %i fields for stanza type %s but got %i)r�r�r�r�zmapping stanza is not supportedr�r(r)rCrEzUnknown address family %s)r>rGr?zUnsupported method %s)r=rBz!stanza type %s is not implementedz,final parsed interfaces: %s; auto ifaces: %s)r�rrerr$ra�KeyErrorr#r��addrb�NotImplementedError)rr��fieldlenr�r}r��
in_options�	in_familyr��fields�exp_lens           rr]zNetplanMigrate.parse_ifupdownhsJ���Q��q�`a�lm�n���.�.�w�8Q�R������u���
��	��'	[�D��Z�Z�\�F�

K�"�6�!�9�-���
�
�D�f�g�V�!�
� �	��6�{�g��k�)� �!S�")�6�!�9�c�&�k�A�o�!F�"G�H�H��a�y�C�C�������#����i�'� �!B�C�C����l�*�����g�%��!�9�$5�5�$�%@�6�!�9�%L�M�M��!�9�$B�B�$�%<�v�a�y�%H�I�I�#�A�Y�
�"�1�I�	�TZ�[\�T]�jl�Im��!�!�&��)�[�]�;�I�F�)�*M�PV�WX�PY�*Y�Z�Z�O'	[�R	�
�
�D�f�d�S���~���C�
K���M�M�"H�*�VZ�[�JN�*�*�^_�*�J`�ab�Jc�F�:�&�y�1�)�<�V�A�Y�G��$�%=��q�	�%I�J�J�
K�s�#E.�.AG	�7G	)rO)�__name__�
__module__�__qualname__rrr)r-r:r5r�r]�
__classcell__)rs@rrr$s/���'�)�:"�&
(��HC�T$�L?rr)�__doc__r$ror&r�rrqr8�ImportError�collectionsrrgr<r�NetplanCommandr�rr�<module>r�s[��$#��	�
�	�����G�$���C�U�)�)�C�����G��s�A�A�A